package com.quasar.hpatient.bean.home_medicine;

import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;

import java.util.List;

import lib.quasar.recycler.model.MultModel;

public final class MedicineBean implements Parcelable {

    public static final Creator<MedicineBean> CREATOR = new Creator<MedicineBean>() {
        @Override
        public MedicineBean createFromParcel(Parcel in) {
            return new MedicineBean(in);
        }

        @Override
        public MedicineBean[] newArray(int size) {
            return new MedicineBean[size];
        }
    };
    private long patientid;
    private String prescription_date = "";
    private List<MedicineItemBean> datas;

    public MedicineBean() {
    }

    protected MedicineBean(Parcel in) {
        patientid = in.readLong();
        prescription_date = in.readString();
        datas = in.createTypedArrayList(MedicineItemBean.CREATOR);
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeLong(patientid);
        dest.writeString(prescription_date);
        dest.writeTypedList(datas);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    public long getPatientid() {
        return patientid;
    }

    public void setPatientid(long patientid) {
        this.patientid = patientid;
    }

    public String getPrescription_date() {
        return prescription_date;
    }

    public void setPrescription_date(String prescription_date) {
        this.prescription_date = prescription_date;
    }

    public List<MedicineItemBean> getDatas() {
        return datas;
    }

    public void setDatas(List<MedicineItemBean> datas) {
        this.datas = datas;
    }

    @Override
    public String toString() {
        return "MedicineTodayBean{" +
                "patientid=" + patientid +
                ", prescription_date='" + prescription_date + '\'' +
                ", datas=" + datas +
                '}';
    }

    public final static class MedicineItemBean implements Parcelable {

        public static final Creator<MedicineItemBean> CREATOR = new Creator<MedicineItemBean>() {
            @Override
            public MedicineItemBean createFromParcel(Parcel in) {
                return new MedicineItemBean(in);
            }

            @Override
            public MedicineItemBean[] newArray(int size) {
                return new MedicineItemBean[size];
            }
        };
        private int period_length;
        private int use_interval;
        private String mname = "";
        private String dose_name = "";
        private String packages = "";
        private String period_begindate = "";
        private String remark = "";
        private List<MedicineItemDetailBean> use_detail = null;

        public MedicineItemBean() {
        }

        protected MedicineItemBean(Parcel in) {
            period_length = in.readInt();
            use_interval = in.readInt();
            mname = in.readString();
            dose_name = in.readString();
            packages = in.readString();
            period_begindate = in.readString();
            remark = in.readString();
            use_detail = in.createTypedArrayList(MedicineItemDetailBean.CREATOR);
        }

        @Override
        public void writeToParcel(Parcel dest, int flags) {
            dest.writeInt(period_length);
            dest.writeInt(use_interval);
            dest.writeString(mname);
            dest.writeString(dose_name);
            dest.writeString(packages);
            dest.writeString(period_begindate);
            dest.writeString(remark);
            dest.writeTypedList(use_detail);
        }

        @Override
        public int describeContents() {
            return 0;
        }

        public String getMname() {
            return mname;
        }

        public void setMname(String mname) {
            this.mname = mname;
        }

        public int getPeriod_length() {
            return period_length;
        }

        public void setPeriod_length(int period_length) {
            this.period_length = period_length;
        }

        public String getDose_name() {
            return dose_name;
        }

        public void setDose_name(String dose_name) {
            this.dose_name = dose_name;
        }

        public String getPackages() {
            return packages;
        }

        public void setPackages(String packages) {
            this.packages = packages;
        }

        public String getPeriod_begindate() {

            if (TextUtils.isEmpty(period_begindate)) {
                return "未知时间";
            } else if (period_begindate.length() >= 10) {
                return period_begindate.substring(0, 10);
            } else {
                return period_begindate;
            }
        }

        public void setPeriod_begindate(String period_begindate) {
            this.period_begindate = period_begindate;
        }

        public int getUse_interval() {
            return use_interval;
        }

        public void setUse_interval(int use_interval) {
            this.use_interval = use_interval;
        }

        public String getRemark() {
            return remark;
        }

        public void setRemark(String remark) {
            this.remark = remark;
        }

        public List<MedicineItemDetailBean> getUse_detail() {
            return use_detail;
        }

        public void setUse_detail(List<MedicineItemDetailBean> use_detail) {
            this.use_detail = use_detail;
        }

        public String getMethod() {
            if (use_interval == 7) {
                return "每周服用";
            } else if (use_interval == 30) {
                return "每月服用";
            } else if (use_interval == 1) {
                return "每天服用";
            } else if (use_interval == 2) {
                return "隔天服用";
            } else {
                return "隔三天服用";
            }
        }

        @Override
        public String toString() {
            return "MedicineItemBean{" +
                    "period_length=" + period_length +
                    ", use_interval=" + use_interval +
                    ", mname='" + mname + '\'' +
                    ", dose_name='" + dose_name + '\'' +
                    ", packages='" + packages + '\'' +
                    ", period_begindate='" + period_begindate + '\'' +
                    ", remark='" + remark + '\'' +
                    ", use_detail=" + use_detail +
                    '}';
        }

        public final static class MedicineItemDetailBean implements MultModel, Parcelable {

            public static final Creator<MedicineItemDetailBean> CREATOR = new Creator<MedicineItemDetailBean>() {
                @Override
                public MedicineItemDetailBean createFromParcel(Parcel in) {
                    return new MedicineItemDetailBean(in);
                }

                @Override
                public MedicineItemDetailBean[] newArray(int size) {
                    return new MedicineItemDetailBean[size];
                }
            };
            private int use_order;
            private float use_number = 1.00f;
            private String use_time = "00:00:00";

            public MedicineItemDetailBean() {
            }

            protected MedicineItemDetailBean(Parcel in) {
                use_order = in.readInt();
                use_number = in.readFloat();
                use_time = in.readString();
            }

            @Override
            public void writeToParcel(Parcel dest, int flags) {
                dest.writeInt(use_order);
                dest.writeFloat(use_number);
                dest.writeString(use_time);
            }

            @Override
            public int describeContents() {
                return 0;
            }

            public String getUse_order() {
                return "第" + use_order + "次";
            }

            public int getOrder() {
                return use_order;
            }

            public void setUse_order(int use_order) {
                this.use_order = use_order;
            }

            public String getShortUse_time() {

                if (TextUtils.isDigitsOnly(use_time)) {
                    return "未知时间";
                } else {
                    return use_time.substring(0, 5);
                }
            }
            public String getUse_time() {

                if (TextUtils.isDigitsOnly(use_time)) {
                    return "未知时间";
                } else {
                    return use_time;
                }
            }

            public void setUse_time(String use_time) {
                this.use_time = use_time;
            }

            public float getUse_number() {
                return use_number;
            }

            public void setUse_number(float use_number) {
                this.use_number = use_number;
            }

            public String getValue() {
                return String.valueOf(use_number);
            }

            @Override
            public int getMultType() {

                if (use_order == Integer.MIN_VALUE) {
                    return MultModel.TYPE_0;
                } else {
                    return MultModel.TYPE_1;
                }
            }

            @Override
            public String toString() {
                return "MedicineItemDetailBean{" +
                        "use_order=" + use_order +
                        ", use_number=" + use_number +
                        ", use_time='" + use_time + '\'' +
                        '}';
            }

            public boolean needCheck() {

                return null == use_time || use_time.isEmpty() ||
                        use_time.equals("08:00") ||
                        use_time.equals("09:00") ||
                        use_time.equals("12:00") ||
                        use_time.equals("16:00") ||
                        use_time.equals("21:00") ||
                        use_time.equals("22:00") ||
                        use_time.equals("23:00");
            }
        }
    }
}
